home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93c.txt / 000010_icon-group-sender _Mon Jul 12 15:57:36 1993.msg < prev    next >
Internet Message Format  |  1994-02-02  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 12 Jul 1993 14:07:01 MST
  2. Date: Mon, 12 Jul 93 15:57:36 CDT
  3. From: "Richard L. Goerwitz" <goer@midway.uchicago.edu>
  4. Message-Id: <9307122057.AA02178@midway.uchicago.edu>
  5. To: icon-group@cs.arizona.edu
  6. Subject: sortff
  7. Status: R
  8. Errors-To: icon-group-errors@cs.arizona.edu
  9.  
  10. I've received several requests for this, so here goes.
  11. It's fairly new, and I haven't tested it in a broad
  12. range of contexts, so please feel free to post bug fixes
  13. or useful modifications....
  14.  
  15. -Richard
  16.  
  17. ############################################################################
  18. #
  19. #    Name:     sortff.icn
  20. #
  21. #    Title:     sortf with multiple field arguments
  22. #
  23. #    Author:     Richard L. Goerwitz
  24. #
  25. #    Version: 1.1
  26. #
  27. ############################################################################
  28. #
  29. #  Sortff is like sortf(), except takes an unlimited number of field
  30. #  arguments.  E.g. if you want to sort a list of structures on field
  31. #  5, and (for those objects that have the same field 5) do a sub-sort
  32. #  on field 2, you would use "sortff(list_of_objects, 5, 2)."
  33. #
  34. ############################################################################
  35.  
  36. procedure sortff(arglst[])
  37.  
  38.     local sortfield, i, old_i
  39.  
  40.     *arglst[1] <= 1 | *arglst = 1 & { return arglst[1] }
  41.     sortfield := arglst[2]        | { return sortf(arglst[1]) }
  42.     arglst[1] := sortf(arglst[1], sortfield)
  43.     
  44.     old_i := 1
  45.     every i := old_i+1 to *arglst[1] do {
  46.         if not (arglst[1][old_i][sortfield] === arglst[1][i][sortfield])
  47.     then {
  48.         return sortff!(push(arglst[3:0], arglst[1][old_i : i])) |||
  49.            sortff!(push(arglst[2:0], arglst[1][i     : 0]))
  50.     }
  51.     }
  52.     return sortff!(push(arglst[3:0], arglst[1]))
  53.  
  54. end
  55.